home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / IFF / bmprintc.c < prev    next >
C/C++ Source or Header  |  1986-04-20  |  4KB  |  150 lines

  1.  
  2. /*--------------------------------------------------------------*/
  3. /*                                      */
  4. /*             bmprintc.c                    */
  5. /*                                      */
  6. /* print out a C-language representation of data for bitmap */
  7. /*                                      */ 
  8. /* By Jerry Morrison and Steve Shaw, Electronic Arts.       */
  9. /* This software is in the public domain.              */
  10. /*                                      */
  11. /* This version for the Commodore-Amiga computer.      */
  12. /*                                      */
  13. /*--------------------------------------------------------------*/
  14.  
  15. #include <iff/intuall.h>
  16. #undef NULL
  17. #include <lattice/stdio.h>
  18.  
  19. #define NO 0
  20. #define YES 1
  21.  
  22. static BOOL doCRLF;
  23.  
  24. PrCRLF(fp) FILE *fp; {
  25.     if (doCRLF) fprintf(fp,"%c%c",0xD,0xA); else fprintf(fp,"\n");
  26.     }
  27.     
  28. PrintBob(bm, fp, name) 
  29.     struct BitMap *bm; 
  30.     FILE *fp;
  31.     UBYTE *name; 
  32.     {
  33.     UWORD *wp;
  34.  
  35.     int p,j,nb;
  36.     int nwords = (bm->BytesPerRow/2)*bm->Rows;
  37.     
  38.     fprintf(fp,"/*----- bitmap : w = %ld, h = %ld ------ */",
  39.        bm->BytesPerRow*8, bm->Rows);
  40.  
  41.     PrCRLF(fp);
  42.     
  43.     for (p=0; p<bm->Depth; ++p) {
  44.      wp = (UWORD *)bm->Planes[p];
  45.      fprintf(fp, "/*------ plane # %ld: --------*/",p);
  46.      PrCRLF(fp);
  47.      fprintf(fp, "UWORD %s%c[%ld] = { ", name, (p?('0'+p):' '), nwords);
  48.      PrCRLF(fp);
  49.      for (j = 0 ;  ; j++) {
  50.          for (nb = 0; ; ) {
  51.              fprintf(fp,"  0x%lx", *wp++);
  52.           nb += 2;
  53.           if (nb == bm->BytesPerRow) { 
  54.               if (j == bm->Rows-1)  goto endplane;
  55.               else { fprintf(fp,", "); PrCRLF(fp);  break; }
  56.               }
  57.           else fprintf(fp,", ");
  58.           }
  59.          }
  60.      endplane: fprintf(fp," };");
  61.      PrCRLF(fp); PrCRLF(fp);
  62.      }
  63.     }
  64.  
  65. PSprite(bm,fp,name,p,dohead) 
  66.     struct BitMap *bm;
  67.     FILE *fp;
  68.     UBYTE *name;
  69.     int p;
  70.     BOOL dohead;
  71.     {
  72.     UWORD *wp0,*wp1;
  73.     int j,nwords;
  74.     int wpl = bm->BytesPerRow/2;
  75.     nwords =  2*bm->Rows + (dohead?4:0);
  76.     wp0 = (UWORD *)bm->Planes[p];
  77.     wp1 = (UWORD *)bm->Planes[p+1];
  78.     fprintf(fp,"UWORD %s[%ld] = {", name, nwords);
  79.     PrCRLF(fp);
  80.     if (dohead){
  81.      fprintf(fp,"  0x0000, 0x0000, /* VStart, VStop */");
  82.      PrCRLF(fp);
  83.      }
  84.     for (j=0 ; j<bm->Rows; j++) {
  85.      fprintf(fp,"  0x%lx, 0x%lx", *wp0, *wp1);
  86.      if (dohead || (j!=bm->Rows-1)) {
  87.           fprintf(fp, ",");
  88.           PrCRLF(fp);
  89.           }
  90.      wp0 += wpl;
  91.      wp1 += wpl;
  92.      }
  93.     if (dohead) fprintf(fp,"  0x0000, 0x0000 }; /* End of Sprite */");
  94.     else fprintf(fp," };");   
  95.     PrCRLF(fp); PrCRLF(fp);
  96.     }
  97.  
  98. static UBYTE one[] = "1";
  99.  
  100. PrintSprite(bm, fp, name, attach, dohdr)
  101.     struct BitMap *bm; FILE *fp;
  102.     UBYTE *name;
  103.     BOOL attach, dohdr;
  104.     {
  105.     fprintf(fp,"/*----- Sprite format: h = %ld ------ */", bm->Rows);
  106.     PrCRLF(fp);
  107.     if (bm->Depth>1) {
  108.      fprintf(fp, "/*--Sprite containing lower order two planes:   */");
  109.         PrCRLF(fp);
  110.      PSprite(bm,fp,name,0,dohdr);
  111.      }
  112.     if (attach && (bm->Depth > 3) ) {
  113.      strcat(name,one);
  114.      fprintf(fp, "/*--Sprite containing higher order two planes:   */");
  115.         PrCRLF(fp);
  116.      PSprite(bm,fp,name,2,dohdr);
  117.      } 
  118.     }
  119.  
  120. #define BOB 0
  121. #define SPRITE 1
  122.     
  123. BMPrintCRep(bm, fp, name, fmt) 
  124.     struct BitMap *bm;   /* Contains the image data */
  125.     FILE *fp;       /* file we will write to */
  126.     UBYTE *name;    /* name associated with the bitmap */   
  127.     UBYTE *fmt;     /* string of characters describing output fmt*/
  128.     {
  129.     BOOL attach, doHdr;
  130.     char c;
  131.     SHORT type;
  132.     doCRLF = NO;
  133.     doHdr = YES;
  134.     type = BOB;
  135.     attach = NO;
  136.     while ( (c=*fmt++) != 0 ) 
  137.      switch (c) {
  138.          case 'b': type = BOB; break;
  139.          case 's': type = SPRITE; attach = NO; break;
  140.          case 'a': type = SPRITE; attach = YES; break;
  141.          case 'n': doHdr = NO; break;
  142.          case 'c': doCRLF = YES; break;
  143.          }
  144.     switch(type) {
  145.      case BOB: PrintBob(bm,fp,name); break;
  146.      case SPRITE:  PrintSprite(bm,fp,name,attach,doHdr); break;
  147.      }
  148.     }
  149.  
  150.